package codec;

import bean.DemoProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by momochen on 2017-07-31.
 */
public class MsgEncode extends MessageToByteEncoder<DemoProtocol> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, DemoProtocol demoProtocol, ByteBuf byteBuf) throws Exception {
        byteBuf.writeInt(demoProtocol.getHead_data());
        byteBuf.writeInt(demoProtocol.getContentLength());
        byteBuf.writeBytes(demoProtocol.getContent());

//        channelHandlerContext.write(byteBuf);
        System.out.println("===>");

//        ProtobufProtocol.ProtobufProtocolBean protobufProtocol = ProtobufProtocol.ProtobufProtocolBean.getDefaultInstance();
    }
}
